package com.yuji.aacar.core.cores.utils;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;

import java.util.ArrayList;
import java.util.List;

/**
 * <li>Package:com.ttp.core.cores.utils
 * <li>Author: lining
 * <li>Date: 2017/2/14
 * <li>Description:
 */

public class CoreENVConfig {

    /** 挡板状态 */
    public static boolean isMockStatus = false;

    public static CoreGlobleSaxParser xmlParser = null;

    public static Context appContext = null;

    public static SharedPreferences sp;

    private static String CONFIG_PREFERENCES = "config_preferences";

    public static Application application;

    public static List<Activity> activitys;

    /**
     * 判断当前请求是否为挡板数据类型
     *
     * @param url 请求的地址
     * @return
     */
    public static boolean currentRequestTypeIsMock(String url) {
        if (url.startsWith("http://")||url.startsWith("https://")) {
            return false;
        }
        return true;
    }

    /**
     * 环境配置
     * @param context 应用上下文
     */
    public static void configurationEnvironment(Context context) {
        sp = context.getSharedPreferences(CONFIG_PREFERENCES,
                Context.MODE_PRIVATE);
        appContext = context;
        activitys = new ArrayList<>();
    }

    /**
     * 项目引用的环境配置解析类
     * @param saxParseService
     */
    public static void setSaxParseService(CoreGlobleSaxParser saxParseService) {
        xmlParser = saxParseService;
    }

    /**
     * 全局管理activity栈空间 新增
     * @param activity
     */
    public static void addCurrentActivity (Activity activity) {
        activitys.add(activity);
    }

    /**
     * 全局管理activity栈空间 删除
     * @param activity
     */
    public static void removeCurrentActivity (Activity activity) {
        activitys.remove(activity);
    }
}
